switchroot: Fix building with musl libc
authorWilliam Manley <will@williammanley.net>
Tue, 26 Jul 2016 16:42:17 +0000 (17:42 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 30 Aug 2016 20:50:33 +0000 (20:50 +0000)
POSIX and GNU define conflicting versions of `strerror_r`.  The GNU
version returns the string but doesn't necessilary write into buf.
The POSIX version writes into buf and returns the length but doesn't
necessilary append a terminate the string with a NUL if it's too long
to fit in buf.

This commit fixes building ostree-prepare-root with musl libc.  The
stripped static build with musl on my machine is 30K vs. 724K with glibc
static and 11K with glibc shared.

Closes: #477
Approved by: cgwalters

src/switchroot/ostree-mount-util.c

index bb27026cd72dad117e11453a4c3207ee135951f7..9789bd863f682fb8470a9566a73b462680ba7d75 100644 (file)
@@ -40,7 +40,13 @@ perrorv (const char *format, ...)
   char buf[1024];
   char *p;
 
+#ifdef _GNU_SOURCE
   p = strerror_r (errno, buf, sizeof (buf));
+#else
+  strerror_r (errno, buf, sizeof (buf));
+  buf[sizeof (buf) - 1] = '\0';
+  p = buf;
+#endif  /* _GNU_SOURCE */
 
   va_start (args, format);